package com.jjty.dataGenerator.bg.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jjty.dataGenerator.bg.entity.ProvinceData;
import com.jjty.dataGenerator.bg.entity.ProvinceInfo;
import com.jjty.dataGenerator.bg.entity.SchoolInfo;
import com.jjty.dataGenerator.bg.mapper.ProvinceMapper;
import com.jjty.dataGenerator.bg.service.ProvinceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * <p>
 * 省份信息 服务实现类
 * </p>
 *
 * @author yourname
 * @since 2024-xx-xx
 */
@Service
public class ProvinceServiceImpl extends ServiceImpl<ProvinceMapper, ProvinceInfo> implements ProvinceService {
    @Autowired
    private ProvinceMapper provinceMapper;

    @Override
    public List<ProvinceInfo> getAllProvinces() {
        return this.list();
    }

    @Override
    public boolean saveProvince(String provinceName, String dataType) {
        provinceMapper.add(provinceName, dataType);
        return true;
    }

    @Override
    public Page getProvinceInfoPage(Page page, ProvinceData param, String keyword) {
        page.setOptimizeCountSql(false);
        List<ProvinceData> provinceData = provinceMapper.getProvinceInfoPage(page,param,keyword);
        return page.setRecords(provinceData);
    }

    @Override
    public List<ProvinceData> getProvinceDataType(String provinceName) {
        return provinceMapper.getProvinceDataType(provinceName);
    }

    @Override
    public List<ProvinceData> getProvince() {
        List<ProvinceData> provinces = provinceMapper.getProvince();
        // 使用 LinkedHashSet 保持元素插入顺序，同时去重
        Set<ProvinceData> provinceSet = new LinkedHashSet<>(provinces);
        return new ArrayList<>(provinceSet);
    }
}